﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Risk.Services;

namespace Site.Models
{
    public class FinishedGamesDTO
    {
        public String Username { get; set; }
        public FinishedGamesDTO(string username)
        {
            Username = username;
        }

        public  List<GameDTO> Games
        {
            get { return DatabaseManager.GetFinishedGameIds().Select(gameId => new GameDTO(gameId)).ToList(); }
        }

        public int PlayerRiskId
        {
            get { return DatabaseManager.GetPlayerRiskId(Username); }
        }


        public string GenerateGameLink(GameDTO game)
        {
            //omdat Html.ActionLink() geen slash toevoegt
            return String.Format("<a href=\"/Game/{0}/{1}/\">Id: {2} Players: {3}</a>", game.Id, PlayerRiskId, game.Id, game.Players.Count); 
        }

        public bool IsWinner(PlayerDTO player)
        {
            return DatabaseManager.IsWinner(player.UniqueId);
        }
        public string GameDuration(int gameId)
        {
            return DatabaseManager.GetGameDuration(gameId).ToString(CultureInfo.InvariantCulture);
        }
    }
}